/**
 * 
 */
package com.hu.ta.assignment5.ui;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import com.hu.ta.assignment5.application.Controller;
import com.hu.ta.assignment5.ui.cui.CUIFrame;
import com.hu.ta.assignment5.util.ConfigurationUtils;

/**
 * UI frame builder
 * 
 * @author cage@g.com
 */
public class UIBuilder extends Observable implements Observer {

	private ArrayList<UIFrame> uiFrameList;

	private final Controller controller;

	public UIBuilder(Controller controller) {
		super();
		this.controller = controller;

		uiFrameList = new ArrayList<UIFrame>();
		uiFrameList.add(new CUIFrame());
	}

	public void startUI() {
		for (UIFrame frame : uiFrameList) {
			frame.setTitle("Assignment 5");

			this.addObserver(frame);

			frame.startUI();
		}

		setObservers();
	}

	public void setObservers() {
		ConfigurationUtils configuration = ConfigurationUtils.getInstance();
		configuration.addObserver(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
	 */
	@Override
	public void update(Observable observable, Object object) {
		// Message for the uis
		if (object instanceof String) {
			setChanged();
			notifyObservers(object);
			return;
		}
	}
}
